<template>
	<div class="alarmConfiguration zy-content">
		<search :columns="searchData" @getSearch="getSearch(arguments)"></search>
		<div class="list-layout mt16">
			<div class="btns clear">
				<span class="title">{{ $t('common.listInformation') }}</span>
				<Button @click="exportTemplateClick">{{ $t('common.batchExport') }}</Button>
				<Button @click="getTableColumns(columns)">
					{{ handleContextMenuStatus ? $t('显示操作栏') : $t('隐藏操作栏') }}
				</Button>
			</div>
			<div class="tableContent">
				<Table
					class="resizable-table"
					border
					@on-column-width-resize="onColumnWidthResize"
					:columns="columnsList"
					ellipsis
					ref="selection"
					stripe
					:data="dataArr"
					@on-selection-change="onSelectChange"
				>
				</Table>
			</div>
			<div class="pageWrap mt16">
				<pageLeftTitle :total="total" :selected="delIds.length" />
				<Page
					:total="total"
					:page-size="pageSize"
					:page-size-opts="pageSizeOption"
					:current="pageNum"
					@on-change="changePageNum"
					@on-page-size-change="changePageSize"
					show-sizer
					show-total
				/>
			</div>
		</div>
	</div>
</template>

<script>
import search from '@/components/curd/searchList.vue';
import fileDownload from 'js-file-download';
import toggleTableOperation from '@/mixins/toggleTableOperation';
export default {
	name: 'pieceReport',
	components: { search },
	mixins: [toggleTableOperation],
	data() {
		return {
			importExcelState: false /*批量导入*/,
			allCheck: false,
			loading: false,
			searchParams: {},
			pageNum: 1,
			pageSize: 10,
			total: 0,

			searchData: [
				// {
				//     title: "功能位置",
				//     key: "mlocation",
				//     type: "cascader",
				//     dicUrl: "/basic/organization/findListByToken?level=0",
				//     params: {
				//         label: "name",
				//         value: "code",
				//         children: "children",
				//     },
				// },
				{
					title: '批次号',
					key: 'batchNumber',
				},
				{
					title: '工单号',
					key: 'workCode',
				},
				{
					title: '工序',
					key: 'productionProcesses',
				},
				{
					title: '设备编号',
					key: 'deviceNo',
				},
				{
					title: '模具编号',
					key: 'moldCode',
				},
				{
					title: '模具名称',
					key: 'moldName',
				},
				{
					title: '产品编号',
					key: 'materialCode',
				},
				{
					title: '产品名称',
					key: 'materialName',
				},
				{
					title: '产品型号',
					key: 'materialModel',
				},
				{
					title: '操作工',
					key: 'operator',
					dicUrl: '/basic/user/searchOAUser',
					params: {
						label: 'username',
						value: 'username',
					},
					type: 'select',
				},
				// {
				// 	title: '生产日期',
				// 	key: 'time',
				// 	type: 'daterange',
				// },
			],
			columns: [
				{
					title: '生产订单号',
					key: 'orderCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '工单号',
					key: 'workCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '工序',
					key: 'productionProcesses',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '功能位置',
					key: 'functionalLocationName',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '设备编号',
					key: 'deviceNo',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '模具编号',
					key: 'moldCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '模具名称',
					key: 'moldName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				// {
				//   title: "型腔数",
				//   key: "realityCavityNum",
				//   minWidth: 150,
				//   align: "center",
				//   resizable: true,
				// },
				{
					title: '产品编号',
					key: 'materialCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},

				{
					title: '产品名称',
					key: 'materialName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品型号',
					key: 'materialModel',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品重量',
					key: 'weight',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品重量单位',
					key: 'weightUnit',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '操作工',
					key: 'operator',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '报工数量',
					key: 'totalReportedQuantity',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '加工单价',
					key: 'machiningPrice',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '计件单价',
					key: 'pieceRatePrice',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '加工总费用',
					key: 'machiningPriceCount',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '计件单价总费用',
					key: 'pieceRatePriceCount',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				// {
				//   title: "标准周期",
				//   key: "moldingCycle",
				//   minWidth: 180,
				//   align: "center",
				//   resizable: true,
				// },
				// {
				//     //title: '操作',
				//     title: `${this.$t('common.operation')}`,
				//     slot: "action",
				//     fixed: 'right',
				//     minWidth: 160,
				//     align: "center"
				// }
			],
			dataArr: [],
			pageSizeOption: [10, 20, 30, 40],
			delIds: [],
			selection: [],
		};
	},
	mounted() {
		this.getTableColumnsWidth(this.columns);
		this.searchList();
		// 基础数据，字典数据
		// this.getDicData('物料类型', this.dicDataList)
	},
	methods: {
		getSearch(arg) {
			this.searchParams = JSON.parse(JSON.stringify(arg[0]));
			if (this.searchParams.time && this.searchParams.time.length > 0) {
				this.searchParams.produceStartTime = this.searchParams.time[0];
				this.searchParams.produceEndTime = this.searchParams.time[1];
				delete this.searchParams.time;
			}
			this.pageNum = 1;
			this.searchList();
		},
		getDicData(name, data) {
			let dataList = data;
			this.axios({
				url: '/dms/faultCategory/dictList',
				method: 'get',
				params: {
					name,
				},
			}).then((res) => {
				if (res.code == 200) {
					dataList = res.data;
				}
			});
		},
		reset() {
			this.searchParams = {};
			this.changeNum();
		},
		//分页
		changeNum() {
			this.pageNum = 1;
			this.searchList();
		},
		changePageSize(pageSize) {
			this.pageSize = pageSize;
			this.searchList();
		},

		changePageNum(val) {
			this.pageNum = val;
			this.searchList();
		},
		//查询列表
		searchList() {
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				...this.searchParams,
			};
			this.axios({
				method: 'post',
				url: '/dms/pRoductionReporting/queryPieceRateList',
				data: params,
			}).then((res) => {
				if (res.code === 200) {
					this.dataArr = res.data.records;
					this.total = res.data.total;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		//导出
		exportTemplateClick() {
			let params = {
				delIds: this.delIds,
			};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			const filName = '计件绩效统计报表';
			this.axios({
				url: '/dms/oee-board/piecePerformanceStatisticsReport/export',
				method: 'post',
				responseType: 'blob',
				data: params,
			}).then((res) => {
				fileDownload(res, filName + '.xls');
			});
		},
	},
};
</script>

<style scoped lang="scss">
.ivu-input-number {
	width: -webkit-fill-available;
}

.row_click {
	cursor: pointer;
	color: rgb(50, 113, 240) !important;
}
</style>
